-- mechanical_spider
-- created by panyl
-- 机械蜘蛛子规则

return {
    -- 学习技能
    apply = function(id, info)
    end,

    -- 检查技能能否升级
    check = function(id)
        local bonusId = EngineeringManualM.query(id, "bonus_id");
        if type(bonusId) ~= "number" then
            return false;
        end

        local bonus = EngineeringManualM.queryBonus(bonusId, "lv1");
        if type(bonus) ~= "table" or sizeof(bonus["summon"]) <= 0 then
            return false;
        end

        -- 如果还未真正开始
        if DungeonM.getState() ~= DUNGEON_GAMING then
            return true;
        end

        local ret = SummonM.canDoSummon(bonus["summon"][1]);
        if ret ~= true then
            trace("mechanical_spider", "当前不能召唤。");

            if type(ret) == "string" then
                doAlert(getLocStr(ret));
            else
                doAlert(getLocStr("duplicate_mechanical_spider"));
            end

            return false;
        end

        if not FormulaM.invoke("HAD_SUMMON_POS") then
            -- 没有位置了
            doAlert(getLocStr("no_pos_to_call_spider"));
            return false;
        end

        return ret;
    end,
};
